package com.tensquare.qa.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    @Query(value = "SELECT * from tb_problem where id in (select problemid from tb_pl where labelid=?) ORDER BY createtime DESC",nativeQuery = true)
    Page<Problem> findNewlist(String labelid, Pageable pageable);

    @Query(value = "SELECT * from tb_problem where id in (select problemid from tb_pl where labelid=?) ORDER BY reply DESC",nativeQuery = true)
    Page<Problem> findHotlist(String labelid, Pageable pageable);

    @Query(value = "SELECT * FROM tb_problem WHERE id in( SELECT problemid FROM tb_pl WHERE labelid=?) AND reply =0 ORDER BY createtime DESC",nativeQuery = true)
    Page<Problem> findWaitlist(String labelid, Pageable pageable);
}
